let express = require('express');
let router = express.Router();
let mongoose = require('mongoose');

//根据所选试卷id，获得所选试卷关联的exercise中的所有内容
//查询已考试卷全部题目->全部试题->全部知识点
router.post('/query', async function (req, resp) {
    //获取当前已考试卷id
    let {testedId} = req.body;
    let re = await mongoose.model('testedsModel').find({
        _id: testedId
    }).populate({
        path: 'testId',
        populate: {
            path: 'exerciseId',
            populate: {
                path: 'pointId',

            }
        }
    })

    if (re.length > 0) {
        resp.send({
            code: 1,
            message: '查询已考试卷全部信息成功!',
            data: re
        });
    } else {
        resp.send({
            code: 2,
            message: '查询已考试卷全部信息失败!',
        });
    }
});

//收藏:前端点收藏后收藏合集新增
router.post('/add', async function (req, resp) {
    //接收前端所选的题目id： exerciseId、学生id：studentId
    let { exerciseId, studentId } = req.body
    let re = await mongoose.model('collectionsModel').create({
        studentId: studentId,
        exerciseId: exerciseId
    });
    resp.send({
        code: 1,
        message: '试题收藏成功!',
        data: re
    });
});


module.exports = router;
